cd FigureA12
use "$path\datasets\rd_dataset.dta", clear


gen base_effect=sum_elected_hcd

gen base_effect_elected_women = base_effect*elected_women
gen base_effect_margin_1=base_effect*margin_1
gen base_effect_inter_1=base_effect*margin_1*elected_women
gen base_effect_margin_2=base_effect*margin_2
gen base_effect_inter_2=base_effect*margin_2*elected_women





local depvar "ch_total_child_places_pc"



****************************************************************************************************

bandwidth_and_weights, depvar(`depvar') var(margin_1)  bwmethod(CCT) kernel(tri) degree(1) number_of_elec(num_of_obs)
ivreg2 `depvar' elected_women base_effect base_effect_elected_women  margin_1 inter_1  base_effect_margin_1 base_effect_inter_1  if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 base_effect_margin_1 base_effect_inter_1)

interact_graph  elected_women base_effect base_effect_elected_women, xtitle("Size of council")
graph export figureA12.pdf, replace


****************************************************************************************************

preserve

keep if jahr==2002| jahr==2008|jahr==2014
bysort gkz jahr: keep if _n==1
replace sum_elected_hcd=total_seats_missing if sum_elected_hcd==.
sum sum_elected_hcd, det

local p5 = r(p5)
local p25 = r(p25)
local p50 = r(p50)
local p75 = r(p75)
local p95 = r(p95)

gen a=.
drop if _n>100
gen xaxis= ((_n)/100)
graph addplot  line a xaxis  , xline(`p5', lcolor(gray) lpattern(shortdash)) xline(`p25', lcolor(gray) lpattern(shortdash)) xline(`p50', lcolor(gray)  lpattern(shortdash)) xline(`p75',lcolor(gray)  lpattern(shortdash))  xline(`p95',lcolor(gray)  lpattern(shortdash)) ytitle("Marginal effect") xtitle("Size of council")  
restore

****************************************************************************************************

graph export figureA12.pdf, replace
cd ..
